package com.cn.bulu.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cn.bulu.pojo.Customer_address;
import com.cn.bulu.pojo.Goods;
import com.cn.bulu.pojo.Merchants;
import com.cn.bulu.service.MerchantsService;
import com.cn.bulu.utils.BuluResult;
import com.cn.bulu.utils.redis.JedisUtil;

@Controller
@RequestMapping("/merchants")
public class MerchantsController {
	@Resource
	private MerchantsService merchantsService;

	// 注册
	@RequestMapping("/insertMerchants")
	@ResponseBody
	public BuluResult insertMerchants(Merchants merchants) {
		BuluResult buluResult = merchantsService.insertMerchants(merchants);
		return buluResult;
	}

	// 下测量
	@RequestMapping("/toAddMeasureIndent")
	@ResponseBody
	public BuluResult toAddMeasureIndent(HttpServletRequest request, String name, String phone, Long subscribeTime,
			Integer roomNumB, String province, String city, String area, String address,String remark) {
		BuluResult buluResult = merchantsService.toAddMeasureIndent(request, name, phone, subscribeTime, roomNumB,
				province, city, area, address,remark);
		return buluResult;
	}

	// 下维修订单
	@RequestMapping("/toAddRepairIndent")
	@ResponseBody
	public BuluResult toAddRepairIndent(HttpServletRequest request, String name, String phone, Long subscribeTime,
			String weiXbody, String province, String city, String area, String address, Double merchantsPrice,
			String baseAddress,String detailAddress,String remark, String takeGoodsTel,Integer isNeedTakeGoods) {
		BuluResult buluResult = merchantsService.toAddRepairIndent(request, name, phone, subscribeTime, weiXbody,
				province, city, area, address, merchantsPrice, baseAddress,detailAddress,remark, takeGoodsTel,isNeedTakeGoods);
		return buluResult;
	}

	// 下安装单
	@RequestMapping("/toAddAnzhuangIndent")
	@ResponseBody
	public BuluResult toAddAnzhuangIndent(HttpServletRequest request, String duogechuanglian, String name, String phone,
			Long subscribeTime, String province, String city, String area, String address,
			String baseAddress,String detailAddress,String remark,String takeGoodsTel,Integer isNeedTakeGoods) {
		BuluResult buluResult = merchantsService.toAddAnzhuangIndent(request, duogechuanglian, name, phone,
				subscribeTime, province, city, area, address, baseAddress,detailAddress,remark, takeGoodsTel,isNeedTakeGoods);
		return buluResult;
	}

	// 查询广告
	@RequestMapping("/selectGuanggao")
	@ResponseBody
	public BuluResult selectGuanggao() {
		BuluResult buluResult = merchantsService.selectGuanggao();
		return buluResult;
	}

	// 检查手机号是否被注册
	@RequestMapping("/selectPhone")
	@ResponseBody
	public BuluResult selectPhone(String phone) {
		BuluResult buluResult = merchantsService.selectPhone(phone);
		return buluResult;
	}

	// 根据手机号查询头像
	@RequestMapping("/selectHeadImg")
	@ResponseBody
	public BuluResult selectHeadImg(String phone) {
		BuluResult buluResult = merchantsService.selectHeadImg(phone);
		return buluResult;
	}

	// 登录
	@RequestMapping("/login")
	@ResponseBody
	public BuluResult login(String account,String imei) {
		BuluResult buluResult = merchantsService.login(account,imei);
		return buluResult;
	}

	// 修改密码
	@RequestMapping("/updatePassword")
	@ResponseBody
	public BuluResult updatePassword(String account) {
		BuluResult buluResult = merchantsService.updatePassword(account);
		return buluResult;
	}

	// 注销
	@RequestMapping("/deleteRedis")
	@ResponseBody
	public BuluResult deleteRedis(HttpServletRequest request) {
		String sign = request.getParameter("sign");
		JedisUtil.removeSessionID(sign, 7);
		BuluResult buluResult = new BuluResult();
		buluResult.setStatus(0);
		return buluResult;
	}

	// 查询进行中订单前端需传给后台一个状态0测量 1安装 2维修
	@RequestMapping("/selectOngoing")
	@ResponseBody
	public BuluResult selectOngoing(HttpServletRequest request, Integer type) {
		BuluResult buluResult = merchantsService.selectOngoing(request, type);
		return buluResult;
	}

	// 查询已完成前端需传给后台一个状态0测量 1安装 2维修
	@RequestMapping("/selectComplete")
	@ResponseBody
	public BuluResult selectComplete(HttpServletRequest request, Integer type, Integer page) {
		BuluResult buluResult = merchantsService.selectComplete(request, type, page);
		return buluResult;
	}

	// 存测量日记
	@RequestMapping("/insertRiji")
	@ResponseBody
	public BuluResult insertRiji(HttpServletRequest request, String name, String phone, String province, String city,
			String area, String address,String remark, String baseAddress, String detailAddress, 
			String takeGoodsTel,String isNeedTakeGoods) {
		BuluResult buluResult = merchantsService.insertRiji(request, name, phone, province, city, area,
				address,remark,baseAddress,detailAddress,takeGoodsTel,isNeedTakeGoods);
		return buluResult;
	}

	// 查测量日记
	@RequestMapping("/selectRiji")
	@ResponseBody
	public BuluResult selectRiji(HttpServletRequest request, Integer page) {
		BuluResult buluResult = merchantsService.selectRiji(request, page);
		return buluResult;
	}

	// 给测量日记添加商品
	@RequestMapping("/insertGoods")
	@ResponseBody
	public BuluResult insertGoods(Integer indentId, Goods goods, String bumishu, String shamishu, String toumishu,
			String imgs,String finishShade) {
		BuluResult buluResult = merchantsService.insertGoods(indentId, goods, bumishu, shamishu, toumishu, imgs,finishShade);
		return buluResult;
	}

	// 查询提现明细
	@RequestMapping("/selectMingxi")
	@ResponseBody
	public BuluResult selectMingxi(HttpServletRequest request,Integer page) {
		BuluResult buluResult = merchantsService.selectMingxi(request,page);
		return buluResult;
	}

	// 查询图标 进行中
	@RequestMapping("/selectJiaobiao")
	@ResponseBody
	public BuluResult selectJiaobiao(HttpServletRequest request) {
		BuluResult buluResult = merchantsService.selectJiaobiao(request);
		return buluResult;
	}

	// 查询维修起步价和备注
	@RequestMapping("/selectWeixiu")
	@ResponseBody
	public BuluResult selectWeixiu(String city,String areaCode){
		BuluResult buluResult = merchantsService.selectWeixiu(city,areaCode);
		return buluResult;
	}

	// 工人接单后应扣金额
	@RequestMapping("/selectYingkou")
	@ResponseBody
	public BuluResult selectYingkou(Integer indentId) {
		BuluResult buluResult = merchantsService.selectYingkou(indentId);
		return buluResult;
	}

	// 取消订单
	@RequestMapping("/deleteIndent")
	@ResponseBody
	public BuluResult deleteIndent(HttpServletRequest request, Integer indentId) {
		BuluResult buluResult = merchantsService.deleteIndent(request, indentId);
		return buluResult;
	}

	// 查询备注
	@RequestMapping("/selectBeizhu")
	@ResponseBody
	public BuluResult selectBeizhu(String city) {
		BuluResult buluResult = merchantsService.selectBeizhu(city);
		return buluResult;
	}

	// 添加对工人的评价
	@RequestMapping("/insertEvaluation")
	@ResponseBody
	public BuluResult insertEvaluation(Integer star, String content, HttpServletRequest request, String imgs,
			Integer indentId) {
		BuluResult buluResult = merchantsService.insertEvaluation(star, content, request, imgs, indentId);
		return buluResult;
	}

	// 删除测量日记
	@RequestMapping("/deleteRiji")
	@ResponseBody
	public BuluResult deleteRiji(Integer indentId) {
		BuluResult buluResult = merchantsService.deleteRiji(indentId);
		return buluResult;
	}

	// 查询个人信息
	@RequestMapping("/selectGeren")
	@ResponseBody
	public BuluResult selectGeren(HttpServletRequest request) {
		BuluResult buluResult = merchantsService.selectGeren(request);
		return buluResult;
	}

	// 修改头像
	@RequestMapping("/updateHeadImg")
	@ResponseBody
	public BuluResult updateHeadImg(HttpServletRequest request, String headImg) {
		BuluResult buluResult = merchantsService.updateHeadImg(request, headImg);
		return buluResult;
	}

	// 修改信息
	@RequestMapping("/updateMerchants")
	@ResponseBody
	public BuluResult updateMerchants(Merchants merchants) {
		BuluResult buluResult = merchantsService.updateMerchants(merchants);
		return buluResult;
	}

	// 根据订单号查询商品
	@RequestMapping("/selectGoods")
	@ResponseBody
	public BuluResult selectGoods(Integer indentId) {
		BuluResult buluResult = merchantsService.selectGoods(indentId);
		return buluResult;
	}

	// 查询地址
	@RequestMapping("/selectAddress")
	@ResponseBody
	public BuluResult selectAddress(HttpServletRequest request) {
		BuluResult buluResult = merchantsService.selectAddress(request);
		return buluResult;
	}

	// 添加地址
	@RequestMapping("/insertAddress")
	@ResponseBody
	public BuluResult insertAddress(HttpServletRequest request, Customer_address address) {
		BuluResult buluResult = merchantsService.insertAddress(request, address);
		return buluResult;
	}

	// 删除地址
	@RequestMapping("/deleteAddress")
	@ResponseBody
	public BuluResult deleteAddress(Integer cuAdId) {
		BuluResult buluResult = merchantsService.deleteAddress(cuAdId);
		return buluResult;
	}

	// 修改地址
	@RequestMapping("/updateAddress")
	@ResponseBody
	public BuluResult updateAddress(Customer_address address,String baseAddress,String detailAddress,
			String takeGoodsTel,String remark) {
		BuluResult buluResult = merchantsService.updateAddress(address,baseAddress,detailAddress,takeGoodsTel,remark);
		return buluResult;
	}

	// 设为默认
	@RequestMapping("/setDefault")
	@ResponseBody
	public BuluResult setDefault(HttpServletRequest request, Integer cuAdId) {
		BuluResult buluResult = merchantsService.setDefault(request, cuAdId);
		return buluResult;
	}

	// 查询钱包
	@RequestMapping("/selectWallet")
	@ResponseBody
	public BuluResult selectWallet(HttpServletRequest request) {
		BuluResult buluResult = merchantsService.selectWallet(request);
		return buluResult;
	}

	// 意见反馈
	@RequestMapping("/insertWenti")
	@ResponseBody
	public BuluResult insertWenti(HttpServletRequest request, String problemCount, String imgs) {
		BuluResult buluResult = merchantsService.insertWenti(request, problemCount, imgs);
		return buluResult;
	}

	// 消息中心
	@RequestMapping("/selectMessage")
	@ResponseBody
	public BuluResult selectMessage(Integer page) {
		BuluResult buluResult = merchantsService.selectMessage(page);
		return buluResult;
	}

	// 验证密码
	@RequestMapping("/updatePhone")
	@ResponseBody
	public BuluResult updatePhone(HttpServletRequest request, String account) {
		BuluResult buluResult = merchantsService.updatePhone(request, account);
		return buluResult;
	}

	// 更换手机号
	@RequestMapping("/replacePhone")
	@ResponseBody
	public BuluResult replacePhone(HttpServletRequest request, String phone) {
		BuluResult buluResult = merchantsService.replacePhone(request, phone);
		return buluResult;
	}

	// 添加房间
	@RequestMapping("/insertRoom")
	@ResponseBody
	public BuluResult insertRoom(Integer indentId, Goods goods) {
		BuluResult buluResult = merchantsService.insertRoom(indentId, goods);
		return buluResult;
	}

	// 根据商品号查看信息
	@RequestMapping("/selectGoodxinxi")
	@ResponseBody
	public BuluResult selectGoodxinxi(Integer goodsId) {
		BuluResult buluResult = merchantsService.selectGoodxinxi(goodsId);
		return buluResult;
	}

	// 修改订单地址
	@RequestMapping("/updateIndent")
	@ResponseBody
	public BuluResult updateIndent(Integer indentId, Customer_address address, String baseAddress,String detailAddress, 
			String isNeedTakeGoods,Long subscribeTime,String takeGoodsTel) {
		BuluResult buluResult = merchantsService.updateIndent(indentId, address, baseAddress,detailAddress,isNeedTakeGoods, subscribeTime,takeGoodsTel);
		return buluResult;
	}

	// 在测量日记中选中几个商品然后生成安装订单
	@RequestMapping("/insertAindent")
	@ResponseBody
	public BuluResult insertAindent(HttpServletRequest request, Integer indentId, String goodsIds, Long subscribeTime) {
		BuluResult buluResult = merchantsService.insertAindent(request, indentId, goodsIds, subscribeTime);
		return buluResult;
	}

	// 删除商品
	@RequestMapping("/deleteGoods")
	@ResponseBody
	public BuluResult deleteGoods(String goodsIds,Integer indentId) {
		BuluResult buluResult = merchantsService.deleteGoods(goodsIds,indentId);
		return buluResult;
	}

	// 根据订单id查询信息
	@RequestMapping("/selectIndent")
	@ResponseBody
	public BuluResult selectIndent(Integer indentId) {
		BuluResult buluResult = merchantsService.selectIndent(indentId);
		return buluResult;
	}

	// 添加银行卡
	@RequestMapping("/insertBankCard")
	@ResponseBody
	public BuluResult insertBankCard(HttpServletRequest request, String boundBank, String bankNumber) {
		BuluResult buluResult = merchantsService.insertBankCard(request, boundBank, bankNumber);
		return buluResult;
	}

	// 查询银行卡
	@RequestMapping("/selectBankCard")
	@ResponseBody
	public BuluResult selectBankCard(HttpServletRequest request) {
		BuluResult buluResult = merchantsService.selectBankCard(request);
		return buluResult;
	}

	// 设为默认银行卡
	@RequestMapping("/updateBankCard")
	@ResponseBody
	public BuluResult updateBankCard(HttpServletRequest request, Integer bankCardId) {
		BuluResult buluResult = merchantsService.updateBankCard(request, bankCardId);
		return buluResult;
	}

	// 删除银行卡
	@RequestMapping("/deleteBankCard")
	@ResponseBody
	public BuluResult deleteBankCard(Integer bankCardId) {
		BuluResult buluResult = merchantsService.deleteBankCard(bankCardId);
		return buluResult;
	}

	// 查询版权信息
	@RequestMapping("/selectCopyright")
	@ResponseBody
	public BuluResult selectCopyright() {
		BuluResult buluResult = merchantsService.selectCopyright();
		return buluResult;
	}

	// 查询说明
	@RequestMapping("/selectAboutMe")
	@ResponseBody
	public BuluResult selectAboutMe() {
		BuluResult buluResult = merchantsService.selectAboutMe();
		return buluResult;
	}

	// 查询软件使用许可协议
	@RequestMapping("/selectVersionIntroduce")
	@ResponseBody
	public BuluResult selectVersionIntroduce() {
		BuluResult buluResult = merchantsService.selectVersionIntroduce();
		return buluResult;
	}

	// 查询平台服务协议
	@RequestMapping("/selectAgreement")
	@ResponseBody
	public BuluResult selectAgreement() {
		BuluResult buluResult = merchantsService.selectAgreement();
		return buluResult;
	}

	// 点击支付
	@RequestMapping("/payMoney")
	@ResponseBody
	public BuluResult payMoney(HttpServletRequest request, Double addPrice, Integer indentId, Integer relievedBao,
			Integer type, Integer motorNum,Integer bigouNum, Integer sizhuagouNum, Double money,Double totalMoney,String differenceIds) {
		BuluResult buluResult = merchantsService.payMoney(request, addPrice, indentId, relievedBao, type, motorNum,
				bigouNum, sizhuagouNum,money,totalMoney,differenceIds);
		return buluResult;
	}

	// 支付订单成功回调
	@RequestMapping("/getAlipayapi")
	@ResponseBody
	public BuluResult getAlipayapi(HttpServletRequest request) {
		BuluResult buluResult = merchantsService.getAlipayapi(request);
		return buluResult;
	}

	// 生成环信账号
	@RequestMapping("/generateAccount")
	@ResponseBody
	public BuluResult generateAccount(HttpServletRequest request) {
		BuluResult buluResult = merchantsService.generateAccount(request);
		return buluResult;
	}

	// 根据余额支付
	@RequestMapping("/payBalance")
	@ResponseBody
	public BuluResult payBalance(HttpServletRequest request, Double addPrice, Integer indentId, Integer relievedBao,
			Integer type, Integer motorNum, String account, Integer bigouNum, Integer sizhuagouNum,Double totalMoney,String differenceIds) {
		BuluResult buluResult = merchantsService.payBalance(request, addPrice, indentId, relievedBao, type, motorNum,
				account, bigouNum, sizhuagouNum,totalMoney,differenceIds);
		return buluResult;
	}

	// 查询是否有银行卡微信支付宝
	@RequestMapping("/selectBangding")
	@ResponseBody
	public BuluResult selectBangding(HttpServletRequest request) {
		BuluResult buluResult = merchantsService.selectBangding(request);
		return buluResult;
	}

	
	/**
	 * 申请提现
	 * @param request
	 * @param money
	 * @param status
	 * @param bankCardId
	 * @param weixin
	 * @param zhifubao
	 * @param password
	 * @param name
	 * @return
	 */
	@RequestMapping("/submitWithdrawal")
	@ResponseBody
	public BuluResult submitWithdrawal(HttpServletRequest request, Double money, Integer status, Integer bankCardId,
			String weixin, String zhifubao, String account, String name) {
		BuluResult buluResult = merchantsService.submitWithdrawal(request, money, status, bankCardId, weixin, zhifubao,
				account, name);
		return buluResult;
	}

	/**
	 * 用户实时充值 XGH
	 * @param request
	 * @param money  
	 * @param cashInter   0支付宝1微信',
	 * @return
	 */
	@RequestMapping("/submitRecharge")
	@ResponseBody
	public BuluResult submitRecharge(HttpServletRequest request, Double money, Integer cashInter) {
		BuluResult buluResult = merchantsService.submitRecarge(request, money, cashInter);
		return buluResult;
	}


	// 查询补差价订单
	@RequestMapping("/selectDifference")
	@ResponseBody
	public BuluResult selectDifference(HttpServletRequest request) {
		BuluResult buluResult = merchantsService.selectDifference(request);
		return buluResult;
	}

	// 修改商品信息风格 和配件
	@RequestMapping("/updateGoodsXinxi")
	@ResponseBody
	public BuluResult updateGoodsXinxi(Integer indentId, Integer goodsId, Integer style, String specials) {
		BuluResult buluResult = merchantsService.updateGoodsXinxi(indentId, goodsId, style, specials);
		return buluResult;
	}

	// TODO 查询该区域是否开通，意味着商家能否下单到此区域
	@RequestMapping("/theAreaIsDredge")
	@ResponseBody
	public BuluResult theAreaIsDredge(String city,String workerSpaceCode) {
		BuluResult buluResult = merchantsService.theAreaIsDredge(city,workerSpaceCode);
		return buluResult;
	}

	@RequestMapping("/getMerchantRules")
	public @ResponseBody BuluResult getMerchantRules(HttpServletRequest request) {
		BuluResult buluResult = merchantsService.getMerchantRules(request);
		return buluResult;
	}

}
